/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.cjb.malacma.rssfeed.entity;

import com.google.gdata.client.GoogleService;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.Transient;

/**
 *
 * @author malacma
 */
@Entity

@NamedQueries(
    @NamedQuery(name="UserContext.findByMail",query="SELECT u FROM UserContext u WHERE u.email= :myEmail")
)
public class UserContext implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private Long id;

    @Column(nullable=false,length=200,updatable=false,unique=true)
    private String email;

    @Column(nullable=false,length=30)
    private String pass;

    @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
    private List<Comment> myComments = new ArrayList<Comment>();

    @ManyToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
    private List<FeedUrl> myFeeds = new ArrayList<FeedUrl>();

    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Calendar lastAcess;

    @Transient
    private HashMap<String,String> mapa = new HashMap<String,String>();

    @Transient
    private GoogleService myService;

    public GoogleService getMyService() {
        return myService;
    }

    public void setMyService(GoogleService myService) {
        this.myService = myService;
    }




    public HashMap<String, String> getMapa() {
        return mapa;
    }

    public void setMapa(HashMap<String, String> mapa) {
        this.mapa = mapa;
    }

    @PreUpdate
    @PrePersist
    private void postLoad(){
        this.lastAcess = Calendar.getInstance();
    }

    public Calendar getLastAcess() {
        return lastAcess;
    }

    public void setLastAcess(Calendar lastAcess) {
        this.lastAcess = lastAcess;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserContext)) {
            return false;
        }
        UserContext other = (UserContext) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "net.cjb.malacma.rssfeed.entity.UserContext[id=" + id + "]";
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<Comment> getMyComments() {
        return myComments;
    }

    public void setMyComments(List<Comment> myComments) {
        this.myComments = myComments;
    }

    public List<FeedUrl> getMyFeeds() {
        return myFeeds;
    }

    public void setMyFeeds(List<FeedUrl> myFeeds) {
        this.myFeeds = myFeeds;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

}
